
#include "dodecahedron.h"

Dodecahedron :: Dodecahedron () : Polyhedra ()
{
	Dodecahedron (this->Size());
}

Dodecahedron :: Dodecahedron (float _size) : Polyhedra (_size)
{
	Dodecahedron (_size, i, r);
}

Dodecahedron :: Dodecahedron (float _size, int _i, float _r) 
	: Polyhedra (_size, _i, _r)
{
	num_pts = 20;
	p = new Point[num_pts];
	SetPoint (_size);
}

Dodecahedron :: ~Dodecahedron ()
{
	Polyhedra::~Polyhedra();
	if (p)
		delete p;
}

void Dodecahedron :: SetPoint (float _size)
{
	Polyhedra :: SetPoint (_size/2.0f);

	float phi = (float)((1.0f + sqrt (5.0f) ) / 2.0f);
	float a = 1.0f / (2.0f * phi);
	float b = phi / 2.0f;
	float u = 1.0f / 2.0f;

	p[1].SetPoint (0, a, b);
	p[0].SetPoint (0, -a, b);
	p[9].SetPoint (0, a, -b);
	p[8].SetPoint (0, -a, -b);

	p[5].SetPoint (u, u, u);
	p[2].SetPoint (-u, u, u);
	p[4].SetPoint (-u, -u, u);
	p[7].SetPoint (u, -u, u);
	p[10].SetPoint (u, u, -u);
	p[12].SetPoint (u, -u, -u);
	p[13].SetPoint (-u, -u, -u);
	p[15].SetPoint (-u, u, -u);

	p[3].SetPoint (-b, 0, a);
	p[6].SetPoint (b, 0, a);
	p[11].SetPoint (b, 0, -a);
	p[14].SetPoint (-b, 0, -a);

	p[16].SetPoint (a, -b, 0);
	p[17].SetPoint (a, b, 0);
	p[18].SetPoint (-a, -b, 0);
	p[19].SetPoint (-a, b, 0);
}

void Dodecahedron :: _Draw (Point* pts)
{
	DrawFace (pts[0], pts[1], pts[2], pts[3], pts[4]);
	DrawFace (pts[7], pts[6], pts[5], pts[1], pts[0]);
	DrawFace (pts[8], pts[9], pts[10], pts[11], pts[12]);
	DrawFace (pts[9], pts[8], pts[13], pts[14], pts[15]);

	DrawFace (pts[11], pts[6], pts[7], pts[16], pts[12]);
	DrawFace (pts[10], pts[17], pts[5], pts[6], pts[11]);
	DrawFace (pts[13], pts[18], pts[4], pts[3], pts[14]);
	DrawFace (pts[14], pts[3], pts[2], pts[19], pts[15]);

	DrawFace (pts[17], pts[19], pts[2], pts[1], pts[5]);
	DrawFace (pts[10], pts[9], pts[15], pts[19], pts[17]);
	DrawFace (pts[7], pts[0], pts[4], pts[18], pts[16]);
	DrawFace (pts[16], pts[18], pts[13], pts[8], pts[12]);
}